ab5aea
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,19 +18,20 @@
package org.springframework.context.annotation;
 
 import java.util.Map;
 import javax.management.MBeanServer;
+import javax.naming.NamingException;
 
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.BeanFactoryAware;
-import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.context.EnvironmentAware;
 import org.springframework.core.annotation.AnnotationAttributes;
 import org.springframework.core.env.Environment;
 import org.springframework.core.type.AnnotationMetadata;
+import org.springframework.jmx.MBeanServerNotFoundException;
 import org.springframework.jmx.export.annotation.AnnotationMBeanExporter;
 import org.springframework.jmx.support.RegistrationPolicy;
 import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean;
-import org.springframework.jndi.JndiObjectFactoryBean;
+import org.springframework.jndi.JndiLocatorDelegate;
 import org.springframework.util.Assert;
 import org.springframework.util.ClassUtils;
 import org.springframework.util.StringUtils;
@@ -119,21 +120,26 @@
public class MBeanExportConfiguration implements ImportAware, EnvironmentAware,
 	}
 
 
-	private static enum SpecificPlatform {
+	public static enum SpecificPlatform {
 
 		WEBLOGIC("weblogic.management.Helper") {
 			@Override
-			public FactoryBean<?> getMBeanServerFactory() {
-				JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
-				factory.setJndiName("java:comp/env/jmx/runtime");
-				return factory;
+			public MBeanServer getMBeanServer() {
+				try {
+					return new JndiLocatorDelegate().lookup("java:comp/env/jmx/runtime", MBeanServer.class);
+				}
+				catch (NamingException ex) {
+					throw new MBeanServerNotFoundException("Failed to retrieve WebLogic MBeanServer from JNDI", ex);
+				}
 			}
 		},
 
 		WEBSPHERE("com.ibm.websphere.management.AdminServiceFactory") {
 			@Override
-			public FactoryBean<MBeanServer> getMBeanServerFactory() {
-				return new WebSphereMBeanServerFactoryBean();
+			public MBeanServer getMBeanServer() {
+				WebSphereMBeanServerFactoryBean fb = new WebSphereMBeanServerFactoryBean();
+				fb.afterPropertiesSet();
+				return fb.getObject();
 			}
 		};
 
@@ -143,19 +149,7 @@
public class MBeanExportConfiguration implements ImportAware, EnvironmentAware,
 			this.identifyingClass = identifyingClass;
 		}
 
-		public MBeanServer getMBeanServer() {
-			Object server;
-			try {
-				server = getMBeanServerFactory().getObject();
-				Assert.isInstanceOf(MBeanServer.class, server);
-				return (MBeanServer) server;
-			}
-			catch (Exception ex) {
-				throw new IllegalStateException(ex);
-			}
-		}
-
-		protected abstract FactoryBean<?> getMBeanServerFactory();
+		public abstract MBeanServer getMBeanServer();
 
 		public static SpecificPlatform get() {
 			ClassLoader classLoader = MBeanExportConfiguration.class.getClassLoader();
